<?php

namespace YmPhp\Admin\Http\Controllers\Setting;

use YmPhp\Admin\Http\Repositories\SystemReport;
use YmPhp\Admin\Form;
use YmPhp\Admin\Grid;
use YmPhp\Admin\Show;
use YmPhp\Admin\Http\Controllers\AdminController;

class SystemReportController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new SystemReport(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('uid');
            $grid->column('reson');
            $grid->column('name');
            $grid->column('mobile');
//            $grid->column('description')->width(300);
            $grid->column('referer')->display(function ($value) {
                $description = mb_substr($this->description, 0, 14) . '....';
                $html = "<pre class='dump'>
    <b>描述</b> : $description,
    <b>链接</b> : <a href='$value' target=\"_blank\">点击详情</a>
</pre>";
                return $html;
            })->width(280);
            $grid->column('crts')->display(function ($value) {
                return date('Y-m-d H:i:s', $value);
            })->width(100);
            $grid->column('status')->select(['0' => '未处理', '1' => '已处理', '2' => '忽略']);
            $grid->disableEditButton();
            $grid->disableViewButton();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new SystemReport(), function (Show $show) {
            $show->field('id');
            $show->field('reson');
            $show->field('name');
            $show->field('mobile');
            $show->field('description');
            $show->field('referer');
            $show->field('crts');
            $show->field('status');
            $show->field('uid');
            $show->field('douid');
            $show->field('upts');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new SystemReport(), function (Form $form) {
            $form->display('id');
            $form->text('reson');
            $form->text('name');
            $form->text('mobile');
            $form->text('description');
            $form->text('referer');
            $form->text('crts');
            $form->text('status');
            $form->text('uid');
            $form->text('douid');
            $form->text('upts');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
